﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
using System.Collections;
using PsychveyApp1.classes;

namespace PsychveyApp1
{

    public class OpenEndedAnswerSelection : System.Web.UI.WebControls.Panel
    {
        public Table tableMain;
        public Survey currentSurvey;
        public UserAccount currentUser;
        public Question currentQuestion;
        public Answer openEndedAnswer;
        public Label questionText;
        public Label questionStatus;
        public TextBox tbxAnswerTextbox;
        public Label label;
        public ArrayList listOfAnswers;
        public ArrayList answerLabelArray;
        public ArrayList answerCheckboxArray;
        public ArrayList listOfUserAnswers;

        public OpenEndedAnswerSelection(UserAccount user, Survey survey, Question question, ArrayList listOfAnswers, ArrayList listOfUserAnswers)
            : base()
        {
            currentUser = user;
            currentSurvey = survey;
            currentQuestion = question;
            this.listOfAnswers = listOfAnswers;

            tableMain = new Table();
            TableRow row = new TableRow();
            TableCell cell = new TableCell();

            label = new Label();
            cell.ColumnSpan = 2;
            label.Text = "Question No: " + question.questionOrder;
            cell.Controls.Add(label);
            tableMain.Rows.Add(row);
            row.Cells.Add(cell);

           
            //--------------------------
            row = new TableRow();
            cell = new TableCell();
            cell.ColumnSpan = 4;
            questionText = new Label();
            questionText.Text = question.questionsAsked.ToString();
            cell.Controls.Add(questionText);
            row.Cells.Add(cell);
            tableMain.Rows.Add(row);

            row = new TableRow();
            cell = new TableCell();
            questionStatus = new Label();
            cell.ColumnSpan = 2;
            cell.Controls.Add(questionStatus);
            row.Cells.Add(cell);
            tableMain.Rows.Add(row);


            //--------------------------
            this.answerLabelArray = new ArrayList();
            this.answerCheckboxArray = new ArrayList();
            for (int i = 0; i < listOfAnswers.Count; i++)
            {
                row = new TableRow();
                cell = new TableCell();

                tbxAnswerTextbox = new TextBox();
                tbxAnswerTextbox.TextMode = TextBoxMode.MultiLine;
                tbxAnswerTextbox.Width = 500;
                tbxAnswerTextbox.Height = 50;
                if (listOfUserAnswers.Count > 0)
                {
                    if (!((UserAnswer)listOfUserAnswers[0]).answerText.Equals(""))
                    {
                        tbxAnswerTextbox.Text = ((UserAnswer)listOfUserAnswers[0]).answerText;
                    }
                }
                cell.Controls.Add(tbxAnswerTextbox);
                row.Cells.Add(cell);
                tableMain.Rows.Add(row);
            }


            row = new TableRow();
            cell = new TableCell();
            cell.ColumnSpan = 2;
            Image breakLine = new Image();
            breakLine.ImageUrl = ("~/images/breakline.png");
            cell.Controls.Add(breakLine);
            row.Controls.Add(cell);
            tableMain.Rows.Add(row);

            this.Controls.Add(tableMain);

        }

     
    }


}
